import info.gridworld.actor.Bug;
import info.gridworld.grid.Location;

/**
 * A <code>ZBug</code> traces out a  "Z" of a given size. <br /> */
public class ZBug extends Bug
{
    private int steps;
    private int sideLength;
    private int segment;
    /**
     * Constructs a spiral bug that traces a "Z" of a given side length
     * @param length the side length
     */
    public ZBug(int length)
    {
    	setDirection(Location.EAST);
        steps = 0;
        sideLength = length;
        segment = 0;
    }

    /**
     * Moves to the next location of the "Z".
     */
    public void act()
    {
        if (steps < sideLength && segment <= 2)
        {
            if (canMove())
            {
            	move();
                steps++;
            }
        }
        else if (segment == 0) {
        	setDirection(Location.SOUTHWEST);
        	steps = 0;
        	segment++;
        }
        else if (segment == 1) {
        	setDirection(Location.EAST);
        	steps = 0;
        	segment++;
        }
    }
}
